package com.joelaws.prototype.server.meeting;

import java.util.Map;

import com.joelaws.prototype.client.meeting.MeetingType;
import com.joelaws.prototype.client.util.Create;

public abstract class MeetAction {

	private long userOneID;

	private long userTwoID;

	private String userOneQuestion;

	private String userTwoQuestion;

	private Map<String, MeetAction> userOneActionMap;

	private Map<String, MeetAction> userTwoActionMap;

	public MeetAction(long userOneID, long userTwoID, String userOneQuestion, String userTwoQuestion) {
		this.userOneID = userOneID;
		this.userTwoID = userTwoID;
		this.userOneQuestion = userOneQuestion;
		this.userTwoQuestion = userTwoQuestion;
		this.userOneActionMap = Create.newMap();
		this.userTwoActionMap = Create.newMap();
	}

	public String[] getActionChoices(long userID) {
		if (userOneID == userID) {
			return userOneActionMap.keySet().toArray(new String[0]);
		}
		if (userTwoID == userID) {
			return userTwoActionMap.keySet().toArray(new String[0]);
		}
		throw new IllegalArgumentException("UserID " + userID + " is not part of this action.");
	}

	public MeetAction nextAction(String choice, long userID) {
		if (userOneID == userID) {
			MeetAction next = userOneActionMap.get(choice);
			if (next == null) {
				throw new IllegalArgumentException("Unknown choice " + choice + " for user " + userID);
			}
			return next;
		}
		if (userTwoID == userID) {
			MeetAction next = userTwoActionMap.get(choice);
			if (next == null) {
				throw new IllegalArgumentException("Unknown choice " + choice + " for user " + userID);
			}
			return next;
		}
		throw new IllegalArgumentException("UserID " + userID + " is not part of this action.");
	}

	public String getActionQuestion(long userID) {
		if (userOneID == userID) {
			return userOneQuestion;
		}
		if (userTwoID == userID) {
			return userTwoQuestion;
		}
		throw new IllegalArgumentException("UserID " + userID + " is not part of this action.");
	}

	protected void addUserOneAction(String choice, MeetAction nextAction) {
		userOneActionMap.put(choice, nextAction);
	}

	protected void addUserTwoAction(String choice, MeetAction nextAction) {
		userTwoActionMap.put(choice, nextAction);
	}

	public MeetingType getMeetingType() {
		return MeetingType.Unknown;
	}

}
